<template>
  <!--  检索框-->
  <div style="padding-top: 20px">
    <el-select v-model="tableData.tagName" placeholder="文章类别" style="width: 150px">
      <el-option label="高数" value="高数" />
      <el-option label="线代" value="线代" />
      <el-option label="政治" value="政治" />
      <el-option label="英语" value="英语" />
      <el-option label="计算机" value="计算机" />
      <el-option label="医学" value="医学" />
      <el-option label="经济学" value="经济学" />
      <el-option label="电子信息" value="电子信息" />
      <el-option label="金融专硕" value="金融专硕" />
    </el-select>
    <el-select v-model="tableData.viewCounts" placeholder="观看人数" style="width: 100px">
      <el-option label="10" value="10" />
      <el-option label="50" value="50" />
      <el-option label="100" value="100" />
      <el-option label="200" value="200" />
      <el-option label="500" value="500" />
      <el-option label="1000" value="1000" />
      <el-option label="2000" value="2000" />
    </el-select>
    <el-select v-model="tableData.title" placeholder="文章标题" style="width: 150px">
      <el-option label="数据结构" value="数据结构" />
      <el-option label="408" value="408" />
      <el-option label="计算机网络" value="计算机网络" />
      <el-option label="计算机组成原理" value="计算机组成原理" />
      <el-option label="微信小程序" value="微信小程序" />
      <el-option label="大学物理" value="大学物理" />
      <el-option label="高数" value="高数" />
      <el-option label="机械" value="机械" />
      <el-option label="自动化" value="自动化" />
    </el-select>
    <el-button type="primary" plain>检索</el-button>
  </div>

<!--  检索结果表格-->
  <div style="padding-top: 20px">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column fixed prop="id" label="文章id" width="150"/>
      <el-table-column prop="authorId" label="用户Id" width="150" />
      <el-table-column prop="title" label="文章标题" width="200" />
      <el-table-column prop="summary" label="简介" width="300" />
      <el-table-column prop="createDate" label="创建时间" width="300" />
<!--      <el-table-column prop="coverImage" label="封面图片" width="250" />-->
      <el-table-column fixed="right" label="Operations" width="120">
        <template #default="data">
            <el-button size="small" @click="lookButton(data.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

  <div class="demo-pagination-block">
    <div class="demonstration"></div>
    <h4>总页数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </h4>
    <el-pagination
        v-model:current-page=current
        :page-size=size
        :small="small"
        :disabled="disabled"
        :background="background"
        layout="total, prev, pager, next"
        :total=total
        @size-change="getSizeChange"
        @current-change="getCurrentPage"
    />
  </div>
</template>

<script>
import request from "@/utils/request";
import router from "@/router";
import displayArticleView from "@/views/body/displayArticleView";

export default {
  name: "ArticleSearchTable",
  components: {
    displayArticleView
  },

  created() {
    this.load()
  },

  methods: {
    load() {
      let user = sessionStorage.getItem("User")
      this.userId = JSON.parse(user).userId
      request.get("/articles/getNowArticles/"+this.current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("返回错误,返回文章检索页面!")
          router.push("/ArticleSearchView")
        } else {
          if (res.data.records!=null){
            this.tableData=res.data.records
            this.total=res.data.total
            this.size=res.data.size
            this.pages=res.data.pages
          }
          else {
            this.tableData=res.data
          }
        }
      })
    },

    getCurrentPage(current){
      request.get("/articles/getNowArticles/"+current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("用户id返回错误,返回最新文章页面!")
          router.push("/NowView")
        } else {
          this.tableData=res.data.records
          console.log(res.data.records)
          this.total=res.data.total
          this.size=res.data.size
          this.pages=res.data.pages
        }
      })
    },


    lookButton(articleId){
      console.log("点击："+articleId)
      router.push({
        name:"displayArticleView",
        query:{
          articleId: articleId,
        }
      })
    }
  },

  data(){
    return{
      tableData:[
        {
          id:1,
          authorId:'',
          title:'',
          summary:'',
          coverImage:'',
          weight:'',
          tagName:'',
          createDate:'',
          viewCounts:0,
        }
      ],

      userId: '',
      total: 12,
      size: 12,
      current: 1,
      pages: 10,
    }
  }

}
</script>

<style >

</style>